import request from '@/utils/request'

// api地址
const api = {
  list: '/v1/cart/list',
  total: '/v1/cart/total',
  add: '/v1/cart/add',
  update: '/v1/cart/update',
  clear: '/v1/cart/delete'
}

// 购物车列表
export const list = () => {
  return request.get(api.list, {}, { load: false })
}

// 购物车商品总数量
export const total = () => {
  return request.get(api.total, {}, { load: false })
}

// 加入购物车
export const add = (goods_id, product_id, qty) => {
  return request.post(api.add, { goods_id, product_id, qty })
}

// 更新购物车商品数量
export const update = (goods_id, product_id, qty, action) => {
  return request.post(api.update, { goods_id, product_id, qty, action}, { isPrompt: false })
}

// 删除购物车中指定记录
export const clear = (product_ids = []) => {
  return request.post(api.clear, { product_ids })
}
